package com.tyqx.hashchainbiz.controller.wx.accountFirm;

import com.tyqx.hashchainbean.module.WxAccountFirm;
import com.tyqx.hashchainbiz.service.WxAccountFirmService;
import hashchainutil.common.Dto;
import hashchainutil.common.DtoUtil;
import hashchainutil.common.EmptyUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: hashchain-spring
 * @description:
 * @author: Mr.Li
 * @create: 2020-10-30 15:03
 **/
@RestController
@RequestMapping("/wx/accountFirm")
@CrossOrigin
public class WxAccountFirmController {

    @Resource
    private WxAccountFirmService wxAccountFirmService;


    @RequestMapping(value = "/queryAccountFirmList", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmList(){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmList();
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询会计师事务所成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查询到会计师事务所记录");
        }
    }

    @RequestMapping(value = "/addWxAccountFirm1", method = RequestMethod.POST)
    @ResponseBody
    public Dto addWxAccountFirm1(@RequestBody WxAccountFirm wxAccountFirm) throws ParseException {
        String message = "";
        if(EmptyUtils.isNotEmpty(wxAccountFirm)){
            Date currentDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date createTime = sdf.parse(sdf.format(currentDate));
            wxAccountFirm.setCreateDate(createTime);
            wxAccountFirm.setAccountFirmType(1);
            int flag = wxAccountFirmService.insertWxAccountFirm(wxAccountFirm);
            if(flag>0){
                message = "添加查核单位成功";
            }else{
                message =  "添加查核单位失败";
            }
        }else{
            message = "信息为空，添加失败";
        }
        return DtoUtil.returnSuccess(message);
    }

    @RequestMapping(value = "/addWxAccountFirm2", method = RequestMethod.POST)
    @ResponseBody
    public Dto addWxAccountFirm2(@RequestBody WxAccountFirm wxAccountFirm) throws ParseException {
        String message = "";
        if(EmptyUtils.isNotEmpty(wxAccountFirm)){
            Date currentDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date createTime = sdf.parse(sdf.format(currentDate));
            wxAccountFirm.setCreateDate(createTime);
            wxAccountFirm.setAccountFirmType(2);
            int flag = wxAccountFirmService.insertWxAccountFirm(wxAccountFirm);
            if(flag>0){
                message = "添加受查企业成功";
            }else{
                message =  "添加受查企业失败";
            }
        }else{
            message = "信息为空，添加失败";
        }
        return DtoUtil.returnSuccess(message);
    }

    @RequestMapping(value = "/addWxAccountFirm3", method = RequestMethod.POST)
    @ResponseBody
    public Dto addWxAccountFirm3(@RequestBody WxAccountFirm wxAccountFirm) throws ParseException {
        String message = "";
        if(EmptyUtils.isNotEmpty(wxAccountFirm)){
            Date currentDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date createTime = sdf.parse(sdf.format(currentDate));
            wxAccountFirm.setCreateDate(createTime);
            wxAccountFirm.setAccountFirmType(3);
            int flag = wxAccountFirmService.insertWxAccountFirm(wxAccountFirm);
            if(flag>0){
                message = "添加函复机构成功";
            }else{
                message =  "添加函复机构失败";
            }
        }else{
            message = "信息为空，添加失败";
        }
        return DtoUtil.returnSuccess(message);
    }

    @RequestMapping(value = "/queryAccountFirmByOpenId1", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmByOpenId1(String openId){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmByOpenId(openId,1);
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询查核单位成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查到查核单位记录");
        }
    }

    @RequestMapping(value = "/queryAccountFirmByOpenId2", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmByOpenId2(String openId){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmByOpenId(openId,2);
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询受查企业成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查询到受查企业记录");
        }
    }

    @RequestMapping(value = "/queryAccountFirmByOpenId3", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmByOpenId3(String openId){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmByOpenId(openId,1);
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询函复机构成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查询到函复机构记录");
        }
    }

    //查询所有的查核单位
    @RequestMapping(value = "/queryAccountFirmByType1", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmByType1(){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmByType(1);
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询查核单位成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查到查核单位记录");
        }
    }

    //查询所有的受查企业
    @RequestMapping(value = "/queryAccountFirmByType2", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmByType2(){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmByType(2);
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询受查企业成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查到受查企业记录");
        }
    }

    //查询所有的函复机构
    @RequestMapping(value = "/queryAccountFirmByType3", method = RequestMethod.POST)
    @ResponseBody
    public Dto queryAccountFirmByType3(){
        List<WxAccountFirm> wxAccountFirmList = wxAccountFirmService.queryWxAccountFirmByType(3);
        if(wxAccountFirmList.size()>0){
            return DtoUtil.returnSuccess("查询函复机构成功",wxAccountFirmList);
        }else{
            return DtoUtil.returnSuccess("未查到函复机构记录");
        }
    }



}
